package edu.gatech.mobile.scene.ui.manage;

import android.app.ListActivity;
import android.content.Intent;
import android.os.Bundle;
import android.view.View;
import android.widget.AdapterView;
import edu.gatech.mobile.scene.R;
import edu.gatech.mobile.scene.provider.impl.ImageInfoTable;

/**
 * A ListActivity showing all the images in the database
 * @author Jing
 *
 */

public class ManageImageActivity extends ListActivity{
	private ImageListAdapter adapter;
	
	
		
	@Override
	protected void onCreate(Bundle savedInstanceState) {
		super.onCreate(savedInstanceState);
		setContentView(R.layout.manage_file_view);
		initViews();
		
		
	}
	
	@Override
	protected void onResume(){
		super.onResume();
		initViews();
	}

	private void initViews() {
		adapter = new ImageListAdapter(this);
		setListAdapter(adapter);
		getListView().setOnItemClickListener(new AdapterView.OnItemClickListener() {
			public void onItemClick(AdapterView<?> av, View v, int pos,
					long id) {
				onListItemClick(v, pos, id);
			}
		});
	}
	
	/**
	 * click listener for handling each list item click event
	 * @param v the view for the list item
	 * @param position item's position in the list
	 * @param id id associated with this list item.(it's just its position right now)
	 */
	private void onListItemClick(View v, int position, long id) {
		String imageInfo = adapter.getItem(position);
		Bundle bdl = new Bundle();
		bdl.putString(ImageInfoTable.FILE_NAME, imageInfo);
		Intent i = new Intent(ManageImageActivity.this, ImageDetailActivity.class);
		i.putExtras(bdl);
		startActivity(i);
	}
}
